home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
MacGzip 1.0
/
source
/
Mac
/
MacGzip.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-18
|
7KB
|
333 lines
/*
* MacGzip.c
* (C) SPDsoft, August 16, 1995
*
*/
#if GENERATINGCFM && !defined(__MWERKS__)
QDGlobals qd;
#endif
/*
* THINK_C 8.0 extra includes (Not in MacHeaders)
*/
#include <Aliases.h>
#include "Prefs.h"
#include "GzErrors.h"
#include "ErrorStrings.h"
#include "FileTypes.h"
#include "MacGzip.h"
#include "Globals.h"
#include "MacAE.h"
/*
* Globals for the application
*/
PrefsType gPrefs;
AppStatus gApp =
{
nil, /* MenuBar */
nil, /* Cursor */
TRUE, /* StartupFiles */
FALSE, /* PrefsChanged */
FALSE, /* Working */
TRUE, /* InForeground */
FALSE, /* quit */
FALSE, /* Prompt */
0, /* KeysMode */
0, /* KeysOp */
0, /* Op */
nil /* DFolder */
};
TSufMap gSufMap =
{
0, nil,
nil, nil
};
/*
* Prototypes
*/
void about(void);
static void InitTheMac(void);
static void FlushTheMac(void);
static void CenterPicRect(PicHandle thePic, Rect *inRect, Rect *outRect);
static pascal char MyFilter ( DialogPtr, EventRecord*, short* );
extern Boolean DoPrefsDialog(PrefsTypePtr thePrefs, AliasHandle * theFldrAlias);
/*
* main
*/
void main( void )
{
InitTheMac();
while (!EventLoop())
;
FlushTheMac();
}
/******************************************************************************
*
* local functions
*/
static void InitTheMac(void)
{
long gestAEResponse,
gFindFolderResponse,
gestAliasResponse,
gestFSResponse,
gestStdFileResponse;
SysEnvRec theWorld;
AEEventHandlerUPP gMyHandleODoc;
AEEventHandlerUPP gMyHandleOApp;
AEEventHandlerUPP gMyHandlePDoc;
AEEventHandlerUPP gMyHandleQuit;
FlushEvents(everyEvent, 0);
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
MaxApplZone();
MoreMasters();
MoreMasters();
err = noErr;
/*
* sys 7 ?
*/
if ( noErr == (err = Gestalt(gestaltAppleEventsAttr, &gestAEResponse)))
if ( noErr == (err = Gestalt(gestaltFindFolderAttr,&gFindFolderResponse)))
if ( noErr == (err = Gestalt(gestaltAliasMgrAttr, &gestAliasResponse)))
if ( noErr == (err = Gestalt(gestaltFSAttr, &gestFSResponse)))
err = Gestalt(gestaltStandardFileAttr, &gestStdFileResponse);
if (
(
( err != noErr ) ||
((gestAEResponse >> gestaltAppleEventsPresent) & 0x0001) == 0 ||
(gFindFolderResponse & ( 1 << gestaltFindFolderPresent)) == 0 ||
(gestAliasResponse & (1 << gestaltAliasMgrPresent)) == 0 ||
(gestFSResponse & (1 << gestaltHasFSSpecCalls)) == 0 ||
(gestStdFileResponse & (1 << gestaltStandardFile58)) == 0
) ||
(SysEnvirons(curSysEnvVers, &theWorld) != noErr)
)
{
DoError(SYS_ERR,QUIT_ERR,GetErrFmt(GENERIC, OLD_SYSTEM));
}
gApp.hasColorQD = theWorld.hasColorQD;
/*
* Get prefs
*/
if (!GetOrGeneratePrefs(&gPrefs, &gApp.DFolder, kCurrentPrefsTypeVers))
{
/*
* First time
*/
about();
if (DoPrefsDialog(&gPrefs, &gApp.DFolder))
{
if( ( err = SavePrefs( &gPrefs, &gApp.DFolder )) != noErr )
{
DoError(SYS_ERR,QUIT_ERR,GetErrFmt(GENERIC, CANT_SAVE_PREF));
}
}
else
/*
* The user MUST hit OK the first time...
*/
ExitToShell();
}
if ( gPrefs.Compress.IC || gPrefs.Decompress.IC )
if ( InitICMappings( &(gSufMap.ICinst), &(gSufMap.ICmappings) ) )
{
/* couldn't init it */
gPrefs.Compress.IC = gPrefs.Decompress.IC = FALSE;
DoError(NO_ERR,INFO_ERR,GetErrFmt(GENERIC, CANT_GET_IC));
}
if ( gPrefs.Decompress.Fetch )
if ( InitFetchMappings( &(gSufMap.FPrefsSize), &(gSufMap.FPrefs) ) )
{
/* couldn't init it */
gPrefs.Decompress.Fetch = FALSE;
DoError(NO_ERR,INFO_ERR,GetErrFmt(GENERIC, CANT_GET_FETCH));
}
/*
* Install Apple Event Handlers
*/
gMyHandleODoc = NewAEEventHandlerProc (MyHandleODoc);
gMyHandleOApp = NewAEEventHandlerProc (MyHandleOApp);
gMyHandlePDoc = NewAEEventHandlerProc (MyHandlePDoc);
gMyHandleQuit = NewAEEventHandlerProc (MyHandleQuit);
if ( noErr == (err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, gMyHandleODoc,0, FALSE) ))
if ( noErr == (err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gMyHandleOApp,0, FALSE) ))
if ( noErr == (err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, gMyHandlePDoc,0, FALSE) ))
err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, gMyHandleQuit,0, FALSE);
if ( err != noErr )
DoError(SYS_ERR,QUIT_ERR,GetErrFmt(GENERIC, AE_INSTALL));
/*
* GetResources
*/
if ( nil == ( gApp.Cursor = InitAnimatedCursor ( kCalCursorRes )))
{
if ( noErr == (err = ResError()))
err = resFNotFound;
DoError(SYS_ERR,QUIT_ERR,GetErrFmt(RES_MANAGER, RES_NOTFOUND));
}
ClearMenuBar();
if ( nil == (gApp.MenuBar = GetNewMBar( kMainMBAR_ID )))
{
if ( noErr == (err = ResError()))
err = resFNotFound;
DoError(SYS_ERR,QUIT_ERR,GetErrFmt(RES_MANAGER, RES_NOTFOUND));
}
SetMenuBar(gApp.MenuBar);
AddResMenu(GetMHandle(kAppleMenu), 'DRVR');
DrawMenuBar();
}
static void FlushTheMac(void)
{
DisposeICMappings( &gSufMap.ICinst, &gSufMap.ICmappings );
DisposeFetchMappings( &gSufMap.FPrefsSize, &gSufMap.FPrefs );
ReleaseAnimatedCursor(&gApp.Cursor);
DisposeHandle(gApp.MenuBar);
if (gApp.PrefsChanged)
if( ( err = SavePrefs( &gPrefs, &gApp.DFolder )) != noErr )
DoError(SYS_ERR,WARN_ERR,GetErrFmt(GENERIC, CANT_SAVE_PREF));
}
/***************************************************************************
*
* About, Beep and other things
*/
void about( void )
{
GrafPtr savePort;
DialogPtr DlgPtr;
short itemHit;
short itemType;
Handle itemHandle;
Rect itemRect;
PicHandle thePict;
ModalFilterUPP ModalUPP;
if ( nil == (DlgPtr = GetNewDialog(kAboutDLOG_ID, nil, (WindowPtr) -1)))
{
if ( noErr == (err = ResError())) err = resFNotFound;
DoError(SYS_ERR,QUIT_ERR,GetErrFmt(RES_MANAGER, RES_NOTFOUND));
}
ShowWindow(DlgPtr);
SelectWindow(DlgPtr);
GetPort(&savePort);
SetPort(DlgPtr);
GetDialogItem(DlgPtr, kAboutRect, &itemType, &itemHandle, &itemRect);
if ( nil == ( thePict = (PicHandle) GetResource('PICT', kAboutPICT_ID)))
{
if ( noErr == (err = ResError()))
err = resFNotFound;
DoError(SYS_ERR,QUIT_ERR,GetErrFmt(RES_MANAGER, RES_NOTFOUND));
}
CenterPicRect( thePict, &itemRect, &DlgPtr->portRect);
DrawPicture(thePict,&itemRect);
ModalDialog (ModalUPP = NewModalFilterProc (MyFilter), &itemHit);
EraseRect (&DlgPtr->portRect);
ReleaseResource((Handle)thePict);
if ( nil == ( thePict = (PicHandle) GetResource('PICT', kGPLPICT_ID)))
{
if ( noErr == (err = ResError()))
err = resFNotFound;
DoError(SYS_ERR,QUIT_ERR,GetErrFmt(RES_MANAGER, RES_NOTFOUND));
}
CenterPicRect( thePict, &itemRect, &DlgPtr->portRect);
DrawPicture(thePict,&itemRect);
ModalDialog (ModalUPP, &itemHit);
DisposeRoutineDescriptor (ModalUPP);
ReleaseResource((Handle)thePict);
SetPort(savePort);
DisposDialog(DlgPtr);
}
static void CenterPicRect(PicHandle thePic, Rect *inRect, Rect *outRect)
{
short dh,dv;
*inRect = (*thePic)->picFrame;
dh = (outRect->right - (inRect->right - inRect->left)) / 2;
dv = (outRect->bottom - (inRect->bottom - inRect->top)) / 2;
OffsetRect(inRect,dh,dv);
}
static pascal char
MyFilter ( DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
{
return ((theEvent->what == keyDown)||(theEvent->what == mouseDown));
}